package com.baidu.cloudmusic.app

import android.app.Application
import cn.leancloud.LCObject
import cn.leancloud.LeanCloud
import com.baidu.lib_audio.AudioHelper
import com.baidu.lib_common.constant.APPID
import com.baidu.lib_common.constant.APPKEY
import com.baidu.lib_common.constant.NetWorkAvailableEvent
import com.baidu.lib_common.constant.NetWorkLostEvent
import com.baidu.lib_common.constant.SERVER_URL
import com.baidu.lib_common.utils.NetWorkUtils
import com.baidu.lib_leancloud.db.RoomHelper
import com.baidu.lib_leancloud.model.Advertisement
import com.baidu.lib_leancloud.model.Chart
import com.baidu.lib_leancloud.model.Music
import org.greenrobot.eventbus.EventBus

class MyApplication: Application() {
    override fun onCreate() {
        super.onCreate()
        LCObject.registerSubclass(Advertisement::class.java)
        LCObject.registerSubclass(Chart::class.java)
        LCObject.registerSubclass(Music::class.java)
        AudioHelper.init(applicationContext)
        NetWorkUtils.instance.initNetWorkUtils(this)
        LeanCloud.initialize(
            this,
            APPID,
            APPKEY,
            SERVER_URL
        )
        NetWorkUtils.instance.registerNetWorkCallback(
            available ={
                EventBus.getDefault().post(NetWorkAvailableEvent())
            },
            lost = {
                EventBus.getDefault().post(NetWorkLostEvent())
            }
        )
    }

    override fun onLowMemory() {
        super.onLowMemory()
        NetWorkUtils.instance.unRegisterNetWorkCallback()
    }
}